﻿Public Class FrmBusquedaPelicula
    Dim altoDinamico As Integer = 244
    Private _peliculaCodigoDeBarras As String
    Public Property PeliculaCodigoDeBarras() As String
        Get
            Return _peliculaCodigoDeBarras
        End Get
        Set(ByVal value As String)
            _peliculaCodigoDeBarras = value
        End Set
    End Property

    Private Sub FrmBusquedaSocio_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'EjercicioDataSet.Pelicula' table. You can move, or remove it, as needed.
        Me.PeliculaTableAdapter.Fill(Me.EjercicioDataSet.Pelicula)
        'TODO: This line of code loads data into the 'EjercicioDataSet.Alquiler' table. You can move, or remove it, as needed.
        Me.AlquilerTableAdapter.Fill(Me.EjercicioDataSet.Alquiler)
    End Sub

    Private Sub PeliculaDataGridView_SelectionChanged(sender As System.Object, e As System.EventArgs) Handles PeliculaDataGridView.SelectionChanged
        If PeliculaDataGridView.SelectedRows.Count > 0 Then
            PeliculaCodigoDeBarras = CType(CType(PeliculaBindingSource.Current, DataRowView).Row, EjercicioDataSet.PeliculaRow).codigo_barras
            btnAceptar.Enabled = True
        Else
            btnAceptar.Enabled = False
        End If
    End Sub

    Private Sub btnAceptar_Click(sender As System.Object, e As System.EventArgs) Handles btnAceptar.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub lblAlquileres_Click(sender As System.Object, e As System.EventArgs) Handles lblAlquileres.Click
        gbAlquileres.Height -= altoDinamico
        gbAlquileres.Location = New Point(gbAlquileres.Location.X, gbAlquileres.Location.Y + altoDinamico)
        PeliculaDataGridView.Height += altoDinamico
        altoDinamico *= -1
    End Sub

    Private Sub btnBuscar_Click(sender As System.Object, e As System.EventArgs) Handles btnBuscar.Click
        Dim filters As New List(Of String)
        If (Not String.IsNullOrEmpty(txtBusquedaCodigoDeBarras.Text)) Then
            filters.Add("codigo_barras LIKE '%" & txtBusquedaCodigoDeBarras.Text & "%'")
        End If
        If (Not String.IsNullOrEmpty(txtBusquedaNombre.Text)) Then
            filters.Add("nombre LIKE '%" & txtBusquedaNombre.Text & "%'")
        End If
        If (checkBusquedaComboGeneros.Checked) Then
            filters.Add("genero_id = " & CInt(cbBusquedaGeneros.SelectedValue))
        End If
        If (checkBusquedaStock.Checked) Then
            filters.Add("stock = " & numBusquedaStock.Value)
        End If
        If (filters.Count > 0) Then
            PeliculaBindingSource.Filter = filters(0)
            For i As Integer = 1 To filters.Count - 1
                PeliculaBindingSource.Filter += " and " & filters(i)
            Next
        Else
            PeliculaBindingSource.Filter = ""
        End If
    End Sub
End Class